<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="工厂">
              <j-dict-select-tag placeholder="请选择工厂" v-model="queryParam.factory" dictCode="mdm_factory,factory_name,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="母件编码">
              <a-input placeholder="请输入母件编码" v-model="queryParam.materialCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import '@/assets/less/TableExpand.less'
  import {getAction} from "@api/manage";

  export default {
    name: "MdmBomMultiLevelList",
    mixins:[JeecgListMixin],
    components: {
    },
    data () {
      return {
        description: '多级BOM查询',
        // 表头
        columns: [
          {
            title:'工厂',
            align:"center",
            width: 120,
            dataIndex: 'factory_dictText'
          },
          {
            title:'BOM编号',
            align:"center",
            width: 60,
            dataIndex: 'rownum'
          },
          {
            title:'母件编码',
            align:"center",
            width: 160,
            dataIndex: 'pmaterialCode'
          },
          {
            title:'母件描述',
            align:"center",
            width: 200,
            dataIndex: 'pmaterialDesc'
          },
          {
            title:'单位',
            align:"center",
            width: 80,
            dataIndex: 'punitCode_dictText'
          },
          {
            title:'生效日期',
            align:"center",
            width: 120,
            dataIndex: 'peffectiveDate'
          },
          {
            title:'子件编码',
            align:"center",
            width: 160,
            dataIndex: 'materialCode'
          },
          {
            title:'子件描述',
            align:"center",
            width: 200,
            dataIndex: 'materialDesc'
          },
          {
            title:'单位',
            align:"center",
            width: 80,
            dataIndex: 'materialUnitCode_dictText'
          },
          {
            title:'组件数量',
            align:"center",
            width: 80,
            dataIndex: 'partQty'
          },
          {
            title:'BOM用量',
            align:"center",
            width: 80,
            dataIndex: 'sumQty'
          },
          {
            title:'损耗率',
            align:"center",
            width: 80,
            dataIndex: 'lossRate'
          },
          {
            title:'项目文本',
            align:"center",
            width: 80,
            dataIndex: 'projectNote'
          },
          {
            title:'仓储地点',
            align:"center",
            width: 80,
            dataIndex: 'storageLocation'
          },
          {
            title:'用途',
            align:"center",
            width: 80,
            dataIndex: 'bomUseType_dictText'
          },
          {
            title:'版本编号',
            align:"center",
            width: 80,
            dataIndex: 'versionNum'
          },
          {
            title:'工位编号',
            align:"center",
            width: 80,
            dataIndex: 'stationNum'
          },
          {
            title:'生效日期',
            align:"center",
            width: 120,
            dataIndex: 'effectiveDate'
          },
          {
            title:'失效日期',
            align:"center",
            width: 100,
            dataIndex: 'expiryDate'
          },
          {
            title:'消耗方式',
            align:"center",
            width: 100,
            dataIndex: 'consumeType_dictText'
          },
        ],
        url: {
          list: "/mdm/bom/multiLevelList",
        },
        dictOptions:{},
        superFieldList:[],
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 1,
          showTotal: (total, range) => {
            return "共" + total/range[1] + "个BOM"
          },
          showQuickJumper: false,
          showSizeChanger: false,
          total: 0
        },
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      importUpdExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importUpdExcelUrl}`;
      }
    },
    methods: {
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.records.length * res.result.pages;
              this.ipagination.pageSize = res.result.records.length;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
         fieldList.push({type:'popup',value:'materialDesc',text:'物料描述', popup:{code:'mdm_popup_bom_material',field:'material_id',orgFields:'material_id',destFields:'materialId'}})
         fieldList.push({type:'string',value:'factory',text:'工厂',dictCode:''})
         fieldList.push({type:'date',value:'effectiveDate',text:'生效日期'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>